﻿@using OBUCare.Core.Models;
@using OBUCare.Web.Infrastructure ;
@using OBUCare.Web.Areas.Admin.Models;

<center>
<h2>@ViewBag.Title</h2>
</center>

@(Html.Telerik().Grid<DictTypeValueViewModel>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).Text("添加"))
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select("List", "DictTypeValues", new { dictTypeID = ViewBag.DictTypeID })
            .Insert("InsertEditing", "DictTypeValues", new { dictTypeID = ViewBag.DictTypeID })
            .Update("SaveEditing", "DictTypeValues", new { dictTypeID = ViewBag.DictTypeID })
            .Delete("Delete", "DictTypeValues", new { dictTypeID = ViewBag.DictTypeID })      
                    )
        .Columns(columns =>
        {
            columns.Bound(o => o.ID);
            columns.Bound(o => o.DICT_TITLE);
            columns.Bound(o => o.DICT_CODE);            
            columns.Bound(o => o.REMARK);
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(CommonStyleForUI.Grid_ButtuonType).Text("编辑");
                //commands.Delete().ButtonType(CommonStyleForUI.Grid_ButtuonType).Text("删除");
            }).Title("编辑");
            columns.Command(commands =>
            {
                //commands.Edit().ButtonType(CommonStyleForUI.Grid_ButtuonType).Text("编辑");
                commands.Delete().ButtonType(CommonStyleForUI.Grid_ButtuonType).Text("删除");
            }).Title("删除");
            
        })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .ClientEvents(events =>
        {
            events.OnEdit("onEdit");
            events.OnError("onError");
        })
        .Pageable(paging =>
        {
            paging.Style(CommonStyleForUI.Grid_PageStyle)
            .Position(CommonStyleForUI.Grid_PagePosition)
            .PageTo(CommonStyleForUI.Grid_CurrentPage)          
            .PageSize(CommonStyleForUI.Grid_PageSize);
        })
        .Scrollable(scroll => scroll.Height(CommonStyleForUI.Grid_Height))
        .Selectable()
)


<script type="text/javascript">

function onEdit(e) {
    //debugger
    var popup = $("#" + e.currentTarget.id + "PopUp");
    var popupDataWin = popup.data("tWindow");

    //popup.css({ "left": "700px", "top": "400px" });
    popupDataWin.center(); // Use if you'd rather center the dialog instead of explicitly postion it.

    if (e.mode == "insert")
        popupDataWin.title("添加");
    else
        popupDataWin.title("编辑");

    // Hide fields from the pop-up.
    //$(e.form).find("#ID").closest(".editor-field").prev().andSelf().hide();
        
}

function onError(e) {
   
    e.preventDefault();
    /*if (e.XMLHttpRequest.status == "505")
        alert("系统字段不允许删除");
    else if (e.XMLHttpRequest.status == "506")
        alert("系统表不允许删除");
    else*/
    alert(e.XMLHttpRequest.getResponseHeader("message"));
}
</script>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}